package cn.buddha.jesw.mvc.controller;

import cn.buddha.jesw.mvc.service.CommonService;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName SyncController
 * @Author 友野浩二
 * @Date 2019/12/4 12:45
 * @Description Spring MVC 【同步处理】
 * @Version 1.0
 */
@RestController
@Slf4j
public class SyncController {

    @Autowired
    private CommonService commonService;

    @RequestMapping(value = "/sync", method = RequestMethod.GET)
    public String syncFun() {
        log.info("cn.buddha.jesw.mvc.controller.SyncController.syncFun start");

        Stopwatch stopwatch = Stopwatch.createStarted();// 创建自动start的计时器

        String result1 = this.commonService.taskOne("同步1");
        String result2 = this.commonService.taskTwo("同步2");

        log.info("耗时: {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));

        log.info("cn.buddha.jesw.mvc.controller.SyncController.syncFun end");
        return result1 + "; " + result2;
    }

}
